home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
-
- /////////////////////////////////////////////////////////////////////////
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: May 1996
- // Author(s): Barb Balents
- //
- // Description:
- // Create and show a dialog for creating flexors.
- //
- /////////////////////////////////////////////////////////////////////////
-
- //
- // Procedure Name:
- // handleExecError
- //
- // Description:
- // called to clean up when execFlexorCommand is called but the
- // flexor that the user requested was not able to be created
- // (The most likely source of error would be that the user
- // had an invalid selection. For example, you can't make a joint
- // flexor if you do not have a joint in your selection list.)
- //
- // Input Arguments:
- // none
- //
- // Return Value:
- // none
- //
- proc handleExecError(string $oldSelection[])
- {
- // disable position flexor check box
- //
- checkBoxGrp -e -v1 0 positionBox;
-
- // restore the old selection list
- //
- if (size($oldSelection) > 0)
- {
- select -r $oldSelection;
- }
-
- return;
- }
-
- //
- // Procedure Name:
- // execFlexorCommand
- //
- // Description:
- // create a string corresponding to the flexor command based
- // on the UI and execute it
- //
- // Input Arguments:
- // none
- //
- // Return Value:
- // none
- //
- global proc execFlexorCommand ()
- {
- int $doTwoCommands = 0;
- int $flexorIsLattice = 0;
- int $flexorIsCluster = 0;
- int $atJoints = `checkBox -q -v allJoints` || `checkBox -q -v selJoints`;
- int $atBones = `checkBox -q -v allBones` || `checkBox -q -v selBones`;
-
- // all segments but only selected joints or vice versa require
- // different sets of flags so we need two commands
- //
- if ($atJoints && $atBones)
- {
- $doTwoCommands = 1;
- }
-
- string $flexorType = `optionMenuGrp -q -v typeMenu`;
- string $flexorType2;
- string $whereString;
- string $whereString2;
- int $atBindPoseWarning = 0;
-
- $flexorIsLattice = ($flexorType == "lattice");
- $flexorIsCluster = ($flexorType == "jointCluster");
-
- // If the flexor is a lattice, make it a joint or bone lattice
- // according to whether the user asked to have it at bones
- // or at joints.
- //
- // Two commands will be necessary if the user asked to have it
- // at both joints and bones.
- //
- if ($flexorIsLattice)
- {
- string $bpNode[] = `dagPose -q -bp -sl`;
- string $atBindPose[];
- if (! catch ($atBindPose = `eval ("dagPose -q -ap "+$bpNode[0])`)) {
- if (0 != size($atBindPose[0])) {
- $atBindPoseWarning = 1;
- }
- }
-
- if ($atJoints && $atBones)
- {
- $flexorType = "jointLattice";
- $flexorType2 = "boneLattice";
- }
- else if ($atJoints)
- {
- $flexorType = "jointLattice";
- }
- else if ($atBones)
- {
- $flexorType = "boneLattice";
- }
- else
- {
- $flexorType = "lattice";
- }
- }
- else if ($flexorIsCluster)
- {
- $flexorType = "jointCluster";
- }
- else if ($atJoints && $atBones)
- {
- $flexorType2 = $flexorType;
- }
-
- // the whereString's are constructed according to the states of
- // "At Selected Bones", "At All Bones", "At Selected Joints", "At All Joints"
- //
- if ($atJoints && $atBones) {
- $whereString = " -aj ";
- if (`checkBox -q -v allJoints`)
- $whereString += "-ts ";
- $whereString2 = " -ab ";
- if (`checkBox -q -v allBones`)
- $whereString2 += "-ts ";
- } else if ($atJoints) {
- if (`checkBox -q -v allJoints`)
- $whereString = " -aj -ts ";
- else
- $whereString = " -aj ";
- } else if ($atBones) {
- if (`checkBox -q -v allBones`)
- $whereString = "-ab -ts ";
- else
- $whereString = " -ab ";
- }
-
- // start constructing the command string(s) that we will execute
- //
- string $deformCmd;
- string $cmdString = "flexor -typ " + $flexorType + $whereString;
- string $cmdString2 = "flexor -typ " + $flexorType2 + $whereString2;
-
- // If it is a sculpt flexor, get the sculpt-specific data
- // from the UI and add it to the flexor's -dc flag argument
- //
- if ($flexorType == "sculpt")
- {
- $deformCmd = "sculpt";
-
- float $maxDisp = `floatSliderGrp -q -v maxFS`;
- float $dropoff = `floatSliderGrp -q -v dropoffFS`;
-
- // Get the sculpt object dropoff type from the
- // option menu
- //
- string $dropoffType = `optionMenuGrp -q -v sculptDropoffMenu`;
- switch( $dropoffType ) {
- case "None":
- $dropoffType = "none";
- break;
- case "Linear":
- $dropoffType = "linear";
- break;
- default:
- $dropoffType = "none";
- break;
- }
-
- // Get the sculpt object mode setting from
- // the option menu
- //
- string $mode = `optionMenuGrp -q -v sculptModeMenu`;
- switch( $mode ) {
- case "Flip":
- $mode = "flip";
- break;
- case "Project":
- $mode = "project";
- break;
- case "Stretch":
- $mode = "stretch";
- break;
- default:
- $mode = "stretch";
- break;
- }
-
- // Get the sculpt object inside mode setting from
- // the option menu
- //
- string $insideMode = `optionMenuGrp -q -v sculptInsideMenu`;
- switch( $insideMode ) {
- case "Ring":
- $insideMode = "ring";
- break;
- case "Even":
- $insideMode = "even";
- break;
- default:
- $insideMode = "ring";
- break;
- }
-
- $deformCmd += (" -mxd " + $maxDisp);
- $deformCmd += (" -m " + $mode + " -im " + $insideMode);
- $deformCmd += (" -drt " + $dropoffType + " -dds " + $dropoff);
- }
- // if it is a lattice flexor, get the lattice-specific data
- // from the UI and add them to the flexor's -dc flag argument
- //
- else if ($flexorIsLattice)
- {
- $deformCmd = "lattice";
-
- int $sd, $td, $ud;
- $sd = `intSliderGrp -q -v sDiv`;
- $td = `intSliderGrp -q -v tDiv`;
- $ud = `intSliderGrp -q -v uDiv`;
- $deformCmd += (" -dv "+$sd+" "+$td+" "+$ud);
-
- $deformCmd += (" -cp ");
- }
-
- // save the current selection so we can restore it later
- //
- string $selected[];
- $selected = `ls -sl`;
-
- // actually execute the first command
- //
- string $results[];
-
- if (! $flexorIsCluster) {
-
- if ($flexorType == "jointLattice") {
- $cmdString += " -dc " + ("\""+$deformCmd+" -dualBase true \"");
- } else {
- $cmdString += " -dc " + ("\""+$deformCmd+"\"");
- }
- }
- if (catch ($results = `evalEcho $cmdString`) ||
- 0 == size($results))
- {
- // Return here and give the user another chance rather
- // than removing the window.
- //
- if (0 == size($results))
- {
- // cleanup and return
- //
- handleExecError($selected);
- return;
- }
- }
-
- // we do two commands when there are conflicting flags:
- // * lattice at segments and at joints
- // * all segments but only selected joints or vice versa
- //
- if ($doTwoCommands)
- {
- if (size($selected) > 0) {
- select -r $selected;
- } else {
- select -d;
- }
-
- if (! $flexorIsCluster)
- $cmdString2 += " -dc " + ("\""+$deformCmd+"\"");
- catch ($results = `evalEcho $cmdString2`);
- }
-
- // a 0-sized result signals failure. Return here and give the
- // user another chance rather than removing the window.
- //
- if (0 == size($results))
- {
- // cleanup and return
- //
- handleExecError($selected);
- return;
- }
-
- if ($atBindPoseWarning) {
- warning("Skeleton was not at bindPose. Lattice flexors work best when created at bindPose.");
- }
-
- // if the user clicked the positionBox, set the state on the
- // invisible checkBox as a global variable
- //
-
- if (`checkBoxGrp -q -v1 positionBox`) {
- // select the transform above the lattice so that we can position it
- //
- string $currentSelection[];
- $currentSelection = `ls -sl`;
-
- if ($flexorIsLattice && (1 == size($currentSelection)))
- {
- $positionedFlexorLattice=$currentSelection[0];
- string $parents[];
- $parents = `listRelatives -p`;
-
- if (size($parents) > 0)
- select -r $parents[0];
- }
- checkBoxGrp -e -v1 false positionBox;
- } else {
- select -r $selected;
- }
-
- return;
- }
-
- // =============== updateFlexorTypeCB ========
- //
- // update callback for when the flexor type option is changed
- //
- //
- global proc updateFlexorTypeCB()
- {
- string $flexorType = `optionMenuGrp -q -v typeMenu`;
-
- frameLayout -e -enable true flexorBoneFrame;
-
- if ($flexorType == "sculpt")
- {
- frameLayout -e -visible true sculptFrame;
- frameLayout -e -visible false latticeFrame;
- frameLayout -e -visible false clusterFrame;
- }
- else if ($flexorType == "jointCluster")
- {
- // bone flexors are not valid for joint clusters
- //
- frameLayout -e -enable false flexorBoneFrame;
- checkBox -e -v 0 allBones;
- checkBox -e -v 0 selBones;
- frameLayout -e -visible true clusterFrame;
- frameLayout -e -visible false latticeFrame;
- frameLayout -e -visible false sculptFrame;
- }
- else if ($flexorType == "lattice" ||
- $flexorType == "jointLattice" ||
- $flexorType == "boneLattice")
- {
- frameLayout -e -visible true latticeFrame;
- frameLayout -e -visible false sculptFrame;
- frameLayout -e -visible false clusterFrame;
- }
- }
-
- global proc jtsOrBonesCB ()
- //
- // Description:
- // callback for when selected joints/bones checkbox is clicked
- //
- {
- int $atSelJoints = `checkBox -q -v selJoints`;
- int $atSelBones = `checkBox -q -v selBones`;
- int $atAllJoints = `checkBox -q -v allJoints`;
- int $atAllBones = `checkBox -q -v allBones`;
-
- // enable the positionBox if only one of either selJoints or
- // selBones is true and neither allJoints nor allBones is on
- //
- if (($atSelJoints && $atSelBones) || $atAllJoints || $atAllBones)
- {
- checkBoxGrp -e -enable false positionBox;
- }
- else if ($atSelJoints || $atSelBones)
- {
- checkBoxGrp -e -enable true positionBox;
- }
- else
- {
- checkBoxGrp -e -enable false positionBox;
- }
- }
-
- //
- // Procedure Name:
- // createFlexorWin
- //
- // Description:
- // create and show a flexor-creation dialog
- //
- // Input Arguments:
- // none
- //
- // Return Value:
- // none
- //
- global proc createFlexorWin()
- {
- string $winName = "createFlexorDialog";
-
- // if the window already exists, just pop it up to the top
- //
- if (`window -exists $winName`)
- {
- checkBoxGrp -e -v1 0 positionBox;
- showWindow $winName;
- return;
- }
- // create a new dialog and base container layout.
- //
- window -rtf false -ip
- -mnb false -mxb false
- -retain -s false
- -wh 430 310
- -tlc 120 740
- -t "Create Flexor"
- -iconName "Create Flexor"
- $winName;
-
- if (`about -mac`) {
- window -edit -h 325 $winName;
- }
-
- setUITemplate -pushTemplate DefaultTemplate;
-
- // ==================== FLEXOR TYPE OPTIONS =================/
-
- formLayout -nd 100 flexorMainForm;
-
- formLayout flexorTypeForm;
- optionMenuGrp -l "Flexor Type"
- -cw 1 80
- -cc updateFlexorTypeCB typeMenu;
-
- // Get the available types and add them to an
- // option menu
- //
- int $i;
- string $flexList[];
- $flexList = `flexor -q -l`;
- $flexListCount = size($flexList);
-
- menuItem -l lattice latticeItem;
- for ($i = 0; $i < $flexListCount; $i++)
- {
- if ($flexList[$i] != "lattice"
- && $flexList[$i] != "jointLattice"
- && $flexList[$i] != "boneLattice")
- {
- menuItem -l $flexList[$i] ($flexList[$i] + "Item");
- }
- }
-
- setParent -m ..;
-
- button -l "Help..." -w 80 -c "showHelp CreateFlexor" helpButton;
-
- formLayout -e
- -af typeMenu top 0
- -af typeMenu bottom 0
- -an typeMenu right
- -af typeMenu left 0
-
- -af helpButton top 0
- -af helpButton bottom 0
- -af helpButton right 0
- -an helpButton left
- flexorTypeForm;
-
- setParent flexorMainForm;
-
- // ==================== JOINT OPTIONS =================/
-
- frameLayout -l "Joints"
- -bv true -bs "etchedIn" -cll false -cl false
- -la bottom -li 0
- flexorJointFrame;
-
- columnLayout -adj true -cal "left";
-
- checkBox -v 1 -l "At Selected Joint(s) "
- -onc "checkBox -e -v 0 allJoints; jtsOrBonesCB"
- -ofc "jtsOrBonesCB"
- selJoints;
- checkBox -v 0 -l "At All Joint(s)"
- -onc "checkBox -e -v 0 selJoints; jtsOrBonesCB"
- -ofc "jtsOrBonesCB"
- allJoints;
-
- setParent flexorMainForm;
-
- // ==================== BONE OPTIONS =================/
-
- frameLayout -l "Bones"
- -bv true -bs "etchedIn" -cll false -cl false
- -la bottom -li 0
- flexorBoneFrame;
-
- columnLayout -adj true -cal "left";
-
- checkBox -v 0 -l "At Selected Bone(s) "
- -onc "checkBox -e -v 0 allBones; jtsOrBonesCB"
- -ofc "jtsOrBonesCB"
- selBones;
- checkBox -v 0 -l "At All Bone(s)"
- -onc "checkBox -e -v 0 selBones; jtsOrBonesCB"
- -ofc "jtsOrBonesCB"
- allBones;
-
- formLayout -e
- -af flexorTypeForm top 5
- -af flexorTypeForm right 5
- -af flexorTypeForm left 5
- -an flexorTypeForm bottom
-
- -ac flexorJointFrame top 5 flexorTypeForm
- -ap flexorJointFrame right 5 50
- -af flexorJointFrame left 5
-
- -ac flexorBoneFrame left 5 flexorJointFrame
- -ac flexorBoneFrame top 5 flexorTypeForm
- -af flexorBoneFrame right 5
- flexorMainForm;
-
- setParent flexorMainForm;
-
- // ==================== SPECIAL OPTIONS =================/
- //
- // These forms will hold special flexor options that vary depending
- // on the flexor type. We leave them invisible and only show
- // them as needed.
- //
-
- // ==================== SCULPT OPTIONS =================/
-
- setParent flexorMainForm;
-
- frameLayout -l "Sculpt Options"
- -lv true -la bottom -li 0
- -bv true -bs "etchedIn"
- -cll false -cl false
- -visible false
- sculptFrame;
-
- columnLayout -p sculptFrame -adj true -cw 100 cLayout;
- floatSliderGrp -field true -l "Max Displacement"
- -min 0 -max 2 -pre 3 -step 0.1 maxFS;
- floatSliderGrp -field true -l "Dropoff Distance"
- -min 0 -max 20 -pre 3 -step 0.1 dropoffFS;
- columnLayout -co "left" 20;
-
- optionMenuGrp -l "Dropoff Type" -cc updateFlexorTypeCB sculptDropoffMenu;
- menuItem -l "None";
- menuItem -l "Linear";
- setParent -m ..;
-
- optionMenuGrp -l "Mode" -cc updateFlexorTypeCB sculptModeMenu;
- menuItem -l "Stretch";
- menuItem -l "Flip";
- menuItem -l "Project";
- setParent -m ..;
-
- optionMenuGrp -l "Inside Mode" -cc updateFlexorTypeCB sculptInsideMenu;
- menuItem -l "Ring";
- menuItem -l "Even";
- setParent -m ..;
-
- // ==================== LATTICE OPTIONS =================/
-
- setParent flexorMainForm;
-
- frameLayout -l "Lattice Options"
- -lv true -la bottom -li 0
- -bv true -bs "etchedIn"
- -cll false -cl false
- -visible true
- latticeFrame;
-
- columnLayout -adj true -cw 100 cLayout2;
- intSliderGrp -field true -l "S Divisions" -min 2 -max 20 -v 2 -step 1 sDiv;
- intSliderGrp -field true -l "T Divisions" -min 2 -max 20 -v 5 tDiv;
- intSliderGrp -field true -l "U Divisions" -min 2 -max 20 -v 2 uDiv;
-
- checkBoxGrp -v1 0 -l1 "Position the Flexor"
- positionBox;
-
- // ==================== CLUSTER OPTIONS =================/
- //
- // No options - just inform the user
-
- setParent flexorMainForm;
-
- frameLayout -l "Cluster Options"
- -lv true -la bottom -li 0
- -bv true -bs "etchedIn"
- -cll false -cl false
- -visible false
- clusterFrame;
-
- formLayout textForm;
- text -l "No options for Joint Cluster flexors" noOptionText;
- setParent ..;
- formLayout -e
- -af noOptionText left 80
- -af noOptionText top 60
- textForm;
-
- // ==================== CREATE and CLOSE Buttons =================/
-
- setParent flexorMainForm;
-
- button -l "Create" -w 100 -c execFlexorCommand okayButton;
- button -l "Close" -w 100 -c "deleteUI createFlexorDialog" closeButton;
-
- formLayout -e
- -af okayButton left 5
- -an okayButton top
- -ap okayButton right 5 50
- -af okayButton bottom 5
-
- -ac closeButton left 5 okayButton
- -af closeButton right 5
- -an closeButton top
- -af closeButton bottom 5
-
- -ac latticeFrame top 5 flexorBoneFrame
- -af latticeFrame left 5
- -af latticeFrame right 5
- -ac latticeFrame bottom 5 okayButton
-
- -ac sculptFrame top 5 flexorBoneFrame
- -af sculptFrame left 5
- -af sculptFrame right 5
- -ac sculptFrame bottom 5 okayButton
-
- -ac clusterFrame top 5 flexorBoneFrame
- -af clusterFrame left 5
- -af clusterFrame right 5
- -ac clusterFrame bottom 5 okayButton
- flexorMainForm;
-
- updateFlexorTypeCB;
-
- setUITemplate -popTemplate;
- showWindow $winName;
-
- } // createFlexorWin //
-
-